package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.Member;
import com.woniu.supermarket.mapper.MemberMapper;
import com.woniu.supermarket.service.IMemberService;
import com.woniu.supermarket.util.CodeCreateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements IMemberService {
    @Autowired
    MemberMapper memberMapper;
    @Override
    public PageInfo<Member> queryByTel(Integer now, Integer size, String memberTel) {
        PageHelper.startPage(now,size);
        List<Member> mlists = memberMapper.selectByMemberTel(memberTel);
        return new PageInfo<>(mlists);
    }

    @Override
    public int modify(Member member) {
        return memberMapper.updateByPrimaryKey(member);
    }

    @Override
    public int add(Member member) {
        member.setMemberCode(CodeCreateUtil.createMemberCode());
        return memberMapper.insert(member);
    }

    @Override
    public int remove(int id) {
        return memberMapper.deleteByPrimaryKey(id);
    }


}
